RPG Datastructure to associative array

15 pts.
Tags:
AS/400 V6r1m0
RPG Functions
Is there in RPG an API or function available that makes it possible to copy field data  from an RPG-data structure into array elements (transformed in to characters). In php or other language you can use assosiative arrays. For data exchanges something similar would be help full. I imagine me a similar solution with to arrays: One array that stores the element names and one array  that stores the (to text) converted field values. Something like that:
%copyDS2array(&dsname:&ArrayElements:&ArrayValues) 
Otherwise I had to solve it with an external data structure field map...

Software/Hardware used:
V6R1M0

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can use “OCCUR” directly

Example:

D QLI DS OCCURS(5)
D PRODOT 1 1
D PQLI01 2 12 4
D PQLI02 13 23 4
D PQLI03 24 34 4
D PQLI04 35 45 4
D PQLI05 46 56 4
D PQLI06 57 67 4
D PQLI07 68 78 4
D PQLI08 79 89 4
D PQLI09 90 100 4
D PQLI10 101 111 4
D PQLI11 112 122 4
D PQLI12 123 133 4
D PQLITO 134 144 4
…..
…..
C 1 DO 5 Y
C Y OCCUR QLI
C Z-ADD 0 PQLITO
C Z-ADD 0 PQLI01
C Z-ADD 0 PQLI02
C Z-ADD 0 PQLI03
C Z-ADD 0 PQLI04
C Z-ADD 0 PQLI05
C Z-ADD 0 PQLI06
C Z-ADD 0 PQLI07
C Z-ADD 0 PQLI08
C Z-ADD 0 PQLI09
C Z-ADD 0 PQLI10
C Z-ADD 0 PQLI11
C Z-ADD 0 PQLI12
C ENDDO

otherwise traditional method use “MOVEA” instruction.

Bye

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Splat
    You can overlay an array in a data structure:
    D                 Ds                  inz    
    D codes                   1     40    dim(8)
    D code01                  1      5           
    D code02                  6     10           
    D code03                 11     15           
    D code04                 16     20           
    D code05                 21     25           
    D code06                 26     30           
    D code07                 31     35           
    D code08                 36     40
    7,235 pointsBadges:
    report
  • TomLiotta
    One array that stores the element names and one array that stores the (to text) converted field values. ...and... In php or other language you can use assosiative arrays. Generally, no. Using PHP as the primary example, many such languages are "interpreted" rather than compiled. (Yes, there now are some "compilers" for PHP, but they are necessarily platform-dependent. Further, there can be major differences between interpreting source to byte-code and actual "compilation".) Languages intended to be interpreted generally have a much easier time with this kind of thing. Compiled procedural languages often have no such ability, usually because they don't make sense in their optimized environments. And when it gets turned into a question that appears to be about dynamic references to variable names (i.e., "field data from an RPG-data structure"), it goes in an unlikely direction. The field names themselves aren't even available to the compiled program (except potentially in debug mode when debug data is left in the module). But the question is about a very specific technical problem that might have no solution. Instead, please see if you can rephrase it into a business problem. What is the activity that you need to perform? I.e., what are you trying to do? Maybe a resolution can be seen from a different angle. As for the question portion about "(transformed in to characters)", see the EVAL-CORR (Assign corresponding subfields) as a potential starting point. The target DS could, for example, use ZONED subfields to achieve initial character representations of numeric values. Tom
    125,585 pointsBadges:
    report
  • Alexk2012
    Tom, thank you for your answer. I just thought it were not possible, but I was not sure about it. I´m looking for an easy way to communicate with a client thru a socket from a server side RPG-program and push data to the client and back, basing on a associative array, that I would wrap into delimters (XML or anything else). So it had been much more comfortable, to operate the fields with a less number of statements - and I could avoid coding all fields individually. Especially for data structures with many fields it is better to code lesser.
    15 pointsBadges:
    report
  • TomLiotta
    (XML or anything else) In that case, the next suggestion is to go to the i 6.1 Information Center, type { rpg AND xml } (minus the braces) into the search box at the top of the left-hand navigation pane and start at the very first search result. After that, pick a few of the remaining results to get a general feel for things. Tom
    125,585 pointsBadges:
    report
  • Mjhaston
    I might have done something similar to what you are trying to do and used "Splats" suggestion. Here's the snippet: http://www.code400.com/forum/showthread.php/11176-XML-INTO-Question?p=66361#post66361
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following