Fetch Next Record Data

How can we fetch next record data for a particular field in ab initio?
i/p
id sal
101 500
102 800
103 900
105 200
o/p
id sal Pre_sal
101 500 0
102 800 500
103 900 800
105 200 900

Questions by Roshan Abinitiobeginer

Showing Answers 1 - 8 of 8 Answers

ayush kishor

  • Apr 10th, 2017
 

Flow: i/p file -->Reformat--->outut file
Below is the transform for Reformat
/*Reformat operation*/
type val= record
string(",") id;
string("
") prev_sal;
end;
let string("
") prev_sal="0";
out::reformat(in)=
begin
let val new_record = [record id in.id,prev_sal prev_sal];
prev_sal=in.sal;
out.id :: in.id;
out.sal :: in.sal;
out.prev_sal :: new_record.prev_sal;
end;

  Was this answer useful?  Yes

nishi

  • May 2nd, 2017
 

@ayush
Could you please explain this part:
let val new_record = [record id in.id,prev_sal prev_sal];

  Was this answer useful?  Yes

Pulastya

  • May 9th, 2017
 

Through Scan we can do

  Was this answer useful?  Yes

raghu

  • Jul 28th, 2017
 


type temporary_type=record
decimal(",") presal;
decimal(",") pressal;
end; /*Temporary variable*/
temp :: initialize(in) =
begin
temp.presal :: 0;
temp.pressal :: 0;
end;
temp::scan(temp,in)=
begin
temp.presal :: temp.pressal;
temp.pressal :: in.dept;
end;
out :: finalize(temp, in) =
begin
out.id :: in.id;
out.name :: in.name;
out.dept :: in.dept;
out.presal :: temp.presal;
end;

  Was this answer useful?  Yes

Datla Vishnu

  • Mar 20th, 2018
 

You can achieve this by using lookup.
First in phase 1 read the data and write it as lookup using Replicate component.
Then in Second Phase Use reformat and below Logic
out::reformat(in) =
begin
let decimal("") temp_id1 = (in.id - 1);
out.id :: in.id;
out.sal :: in.sal;
out.prev_sal :: if (in.id ==0 ) "0" else lookup("Lookup File",temp_id1).sal;
end;

  Was this answer useful?  Yes

PJ

  • Apr 17th, 2018
 

Another way of doing using SCAN with One Global and One local variables is as below
let decimal()hold_previous_val = 0;
out :: scan(in) =
begin
let decimal()temp_val = hold_previous_val;
hold_previous_val = in.val;
out.id :: in.id;
out.val :: in.val;
out.add_val :: temp_val;
end;

  Was this answer useful?  Yes

neha.nagare

  • Apr 26th, 2018
 

We can achieve this by using reformat component by maintaining current and previous value of the column sal and by updating variable prev_sal with previous record value of column sal.
Please find below code :
let decimal("") prev_sal=0; // global variable to maintain previous value of the sal column
let decimal("") curr_sal=0; // global variable to maintain current value of the sal column
out::reformat(in)=
begin
prev_sal=curr_sal;
if(next_in_sequence()==1)
begin
curr_sal=in.sal;
prev_sal=0;
end
else
curr_sal=in.sal;
out.*::in.*;
out.Pre_Sal :: prev_sal;
end

Sai

  • May 14th, 2018
 

use scan component we have to achieve this scenario and the parameter key is "NULL({})"and find the below explanation.Here i am taking the 2 temporary variables as a,b.
type temporary_type = record
decimal("|") a;
decimal("|") b;
temp::initialize(in) =
begin
temp.a ::0;
temp.b ::0;
end;
temp::scan(temp,in)=
begin
temp.a :: if(in.id==101)temp.a else temp.b;
temp.b :: in.sal;
end;
out::finalize(temp,in)=
begin
out.id :: in.id ;
out.sal :: in.sal;
out.pre_sal :: temp.a;
end;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions