-3

I'm in Charge of an IBM i Series. Now I have to program some new things. I have to read some data from an internally described file and use it in my program but it contains packed decimal data and I'm not quite sure how to handle that.

How do I actually read the packed decimal data in my program?

Is it even possible by %SUBST?

jmarkmurphy
  • 11,030
  • 31
  • 59
Scrober
  • 13
  • 5
  • And your question is what, exactly? – EJoshuaS - Stand with Ukraine Jul 10 '18 at 04:16
  • @EJoshuaS How do i actually read the Packed information in my Program? Is it even possible by %SUBST? – Scrober Jul 10 '18 at 04:49
  • Please clarify this question. I'm assuming by "packed" data you mean data from probably a network source that is bit packed and not the packed RPG data type? Or do you possibly mean packed data structures as in byte aligned rather than 32 or 64 bit word aligned? This could really use an example of the data structure you are trying to parse out. I'm also not sure why you put "free-form RPG" in the title. Do you know how to do this in non free-form and are wondering how to translate this to free form? – Player1st Jul 10 '18 at 15:20
  • No, it is not directly possible to process packed decimal data using `%subst()`. `%subst()` works on character data, and packed decimal is a numeric format, like integer or floating point. I say not directly because you can substring packed data into a data structure that contains a packed field, and use it that way, but David provides the best way to handle this in his answer. – jmarkmurphy Jul 10 '18 at 18:44
  • No need to parse the fields manually with RPG. Use a program described file and declare the fields on the input specifications like the good old days. – James Allman Jul 11 '18 at 13:18
  • @jamesallman thank you for your helpful answer i will test your idea – Scrober Jul 11 '18 at 14:21

1 Answers1

1

Use a data structure to define the data layout, read the data into the structure, and you're all set.

Alternatively, you can define the file using DDS and copy the data from the flat file into the DDS file (using FMTOPT(*NOCHK))

David G
  • 3,940
  • 1
  • 22
  • 30