سؤال

Currently I have an IDescriptor that pulls Sales from another FILE for Period 1,2,3. I want to be able to pull Costs from Period 1,2,3 and subtract the totals to get a profit.

The Current I-Descriptor Statement is:

TRANS(SAS1,ITEM,4,'X');@1<1,1,1>+@1<1,1,2>+@1<1,1,3>
  • 4 = Sales
  • 3 = Cost
  • @1<1,1,1> = Period 1
  • @1<1,1,2> = Period 2
  • @1<1,1,3> = Period 3
  • @1<1,1,4> = Period 4
هل كانت مفيدة؟

المحلول

You are looking for EXTRACT

So, try the following the the loc attribute:

TRANS(SAS1,ITEM,4,'X');EXTRACT(@1,1,1,1)+EXTRACT(@1,1,1,2)+EXTRACT(@1,1,1,3)

The next bit of the question isn't entirely clear to me, so let me know if I've made an incorrect assumption.

Costs come from the current file (the one this dictionary file is) from attribute (field) 3. It has the same format as the data for Sales (<1,1,1 to 3>). In this case you would need to use @RECORD.

TRANS(SAS1,ITEM,4,'X');EXTRACT(@1,1,1,1)+EXTRACT(@1,1,1,2)+EXTRACT(@1,1,1,3);EXTRACT(@RECORD,1,1,1)+EXTRACT(@RECORD,1,1,2)+EXTRACT(@RECORD,1,1,3);@2-@3

So, let's break it down:

  • Read attribute 4 from record ITEM in file SAS1. Return an empty string if the item doesn't exist. Hold this in position 1 (@1):

TRANS(SAS1,ITEM,4,'X');

  • Extract multi-subvalues 1 to 3 from the value in position 1 then add them together (). Hold this in position 2:

EXTRACT(@1,1,1,1)+EXTRACT(@1,1,1,2)+EXTRACT(@1,1,1,3);

  • Extract multi-subvalues 1 to 3 from the current record and add them together. Hold this in position 3:

EXTRACT(@RECORD,1,1,1)+EXTRACT(@RECORD,1,1,2)+EXTRACT(@RECORD,1,1,3);

  • Finally, subtract the value in position 3 (total costs) from the value in position 2 (total sales). As this is the last position, return the result:

@2-@3

نصائح أخرى

The only missing thing in Dan's answer is that you need another TRANS to get your COST field, hence TRANS(SAS1,ITEM,3,'X');

after the first operations on the EXTRACTs.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top