Sat Nov 27, 2021 12:14 am
Login Register Lost Password? Contact Us


OUTPUT module as a dataset

Comments and questions related to the Enterprise Control Language

Wed Feb 03, 2021 12:44 am Change Time Zone

Hi,

I am trying to understand a case where a module could easily be converted to a dataset. The reason why I am trying to do this is that some modules I am working with have 50+ fields, and I would like to be able to have a single output as opposed to 50+ in the ECL IDE or out on the ECL Watch page.

Following is a piece of code I used to test what I am trying to accomplish:

Code: Select all
UNSIGNED firstSettingIn := 2;

MY_LIBIN := INTERFACE
   EXPORT UNSIGNED1 firstSetting := 1;
   EXPORT UNSIGNED1 secondSetting := 5;
   EXPORT BOOLEAN isInternalProduct := TRUE;
END;


myModule := MODULE (MY_LIBIN)
   EXPORT UNSIGNED1 firstSetting := firstSettingIn;
END;
               
                   
OUTPUT(myModule);

OUTPUT(myModule) produces three outputs - one for each variable, which is kind of undesired. See attachment (outputs).

Is there an easy way to do this without having to define a new layout and projecting everything from the module into a dataset? I thought that doing something like the following would work, but it appears that it doesn't:

Code: Select all
modToDataset := DATASET([TRANSFORM(MY_LIBIN,
                             SELF.firstSetting := myModule.firstSetting;
                             SELF := [];)
                        ]);
                       
OUTPUT(modToDataset, NAMED('modToDataset'));

I get an error that is exactly at the end of MY_LIBIN, which makes sense and is kind of expected as MY_LIBIN is not a real layout.

Any other insights on how this could easily be achieved would be appreciated.


Thanks.
Attachments
outputs.jpg
(21.82 KiB) Not downloaded yet
flyer
 
Posts: 8
Joined: Fri Dec 11, 2020 1:58 pm

Wed Feb 03, 2021 6:55 pm Change Time Zone

flyer,
Is there an easy way to do this without having to define a new layout and projecting everything from the module into a dataset?
Short answer: None that I know of (and I tried a couple of ideas before replying).

In fact, I'm surprised that your OUTPUT(myModule) code works at all. I think you're taking advantage of an undocumented "feature" with that one. :)

So here's how I would approach the problem:
Code: Select all
UNSIGNED firstSettingIn := 2;

MY_LIBIN := INTERFACE
   EXPORT UNSIGNED1 firstSetting := 1;
   EXPORT UNSIGNED1 secondSetting := 5;
   EXPORT BOOLEAN isInternalProduct := TRUE;
END;


myModule := MODULE (MY_LIBIN)
   EXPORT UNSIGNED1 firstSetting := firstSettingIn;
END;
               
//my suggested solution:                   
modToDataset(MY_LIBIN i) := FUNCTION
  MY_LIBOUT := RECORD
    i.firstSetting;
    i.secondSetting;
    i.isInternalProduct;
  END;
  ds := DATASET(1,TRANSFORM(MY_LIBOUT,SELF := []));
  RETURN TABLE(ds,MY_LIBOUT);
END;

OUTPUT(modToDataset(myModule), NAMED('modToDataset'));
This is a FUNCTION that takes a parameter of your initial INTERFACE type. The MY_LIBOUT RECORD structure is designed for use by the TABLE function, and the DATASET is just to create a 1-record dataset for the TABLE to operate against, producing the values that are passed in by whatever MODULE instance you pass that implements your INTERFACE. For each INTERFACE you create, you just need one of these FUNCTIONs and it will operate against whatever MODULE instance you pass each time.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1604
Joined: Wed Oct 26, 2011 7:40 pm

Thu Feb 04, 2021 3:30 am Change Time Zone

Hi Richard,

That is what I thought - to your short answer :)

In any case, thank you so much for sharing the way you would approach the problem. It is always nice to be exposed to others' ways of thinking.
flyer
 
Posts: 8
Joined: Fri Dec 11, 2020 1:58 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest

cron