Read A Flat File Using File Layout And Insert Into The Specific Component Using CI ( Bulk Insert )

Read A Flat File Using File Layout And Insert Into The Specific Component Using CI:
Approach:
Get the sample flat file and create a File Layout. 
Create the CI for the component.
Create an AE and drag the File Layout and CI for dynamic code generation in the peoplecode action

Sample Code:
/*******************************************************************************/
Local File &FILE1;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
/* *****************************************************************/
Function StartSession
try
&oSession = %Session;
&oSession.PSMessagesMode = 1;
catch Exception &ex
&LOGFILE.WriteLine(&ex.ToString());
end-try;
End-Function;
/*******************************************************************/
Function ImportData(&RS1 As Rowset)
try
&oEmPDpndtBlInsCi = &oSession.GetCompIntfc(CompIntfc.EM_P_DPNDT_BL_INS_CI);
If &oEmPDpndtBlInsCi = Null Then
errorHandler();
throw CreateException(0, 0, "GetCompIntfc failed");
End-If;

&oEmPDpndtBlInsCi.InteractiveMode = False;
&oEmPDpndtBlInsCi.GetHistoryItems = True;
&oEmPDpndtBlInsCi.EditHistoryItems = False;

&recPerInfo = CreateRecord(Record.EM_PER_INFO);
&recPerInfo1 = CreateRecord(Record.EM_PER_INFO1);
&recBnkInf = CreateRecord(Record.EM_BANK_INFO);
&recdpdntInf = CreateRecord(Record.EM_DPNDNT_INFO);
&LOGFILE.WriteRowset(&RS);
&RS1(1).GetRecord(1).CopyFieldsTo(&recPerInfo);
&oEmPDpndtBlInsCi.EMPLID = &recPerInfo.EMPLID.Value;

rem ***** Execute Get *****;
If Not &oEmPDpndtBlInsCi.Get() Then
rem ***** No rows exist for the specified keys.*****;
errorHandler();
throw CreateException(0, 0, "Get failed");
End-If;

&oEmPerInfo1Collection = &oEmPDpndtBlInsCi.EM_PER_INFO1;
&RS2 = &RS1(1).GetRowset(Scroll.EM_PER_INFO1);
For &i = 1 To &RS2.ActiveRowCount
If &i > 1 Then
&oEmPerInfo1 = &oEmPerInfo1Collection.EM_PER_INFO1.InsertItem(1);
Else
&oEmPerInfo1 = &oEmPerInfo1Collection.Item(1);
End-If;
&RS2.GetRow(&i).GetRecord(Record.EM_PER_INFO1).CopyFieldsTo(&recPerInfo1);
&oEmPerInfo1.EFFDT = &recPerInfo1.EFFDT.Value;
&oEmPerInfo1.SEX = &recPerInfo1.SEX.Value;
&oEmPerInfo1.MAR_STATUS = &recPerInfo1.MAR_STATUS.Value;

End-For;

&RS3 = &RS1(1).GetRowset(Scroll.EM_BANK_INFO);
&oEmBankInfoCollection = &oEmPDpndtBlInsCi.EM_BANK_INFO;
For &j = 1 To &RS3.ActiveRowCount
If &j > 1 Then
&oEmBankInfo = &oEmBankInfoCollection.EM_BANK_INFO.InsertItem(1);
Else
&oEmBankInfo = &oEmBankInfoCollection.Item(&j);
End-If;
&RS3.GetRow(&j).GetRecord(Record.EM_BANK_INFO).CopyFieldsTo(&recBnkInf);
&oEmBankInfo.BANK_NM = &recBnkInf.BANK_NM.Value;
&oEmBankInfo.BANK_ACCOUNT_NUM = &recBnkInf.BANK_ACCOUNT_NUM.Value;
End-For;

rem ***** End: Get/Set Component Interface Properties *****;
rem ***** Execute Save *****;
If Not &oEmPDpndtBlInsCi.Save() Then;
rem errorHandler();
throw CreateException(0, 0, "Save failed");
End-If;
catch Exception &ex
&fileLog.WriteLine(&ex.ToString());
end-try;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
&FILE1 = GetFile("C:\Documents and Settings\pmundhr\Desktop\dpndBlkIns.csv", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("C:\Documents and Settings\pmundhr\Desktop\dpndBlkIns.csv.err", "W", %FilePath_Absolute);
StartSession();
&FILE1.SetFileLayout(FileLayout.EM_P_DPNDT_IB);
&LOGFILE.SetFileLayout(FileLayout.EM_P_DPNDT_IB);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.EM_PER_INFO, CreateRowset(Record.EM_PER_INFO1), CreateRowset(Record.EM_BANK_INFO), CreateRowset(Record.EM_DPNDNT_INFO));

&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null;
ImportData(&RS1);
&RS1 = &FILE1.ReadRowset();
End-While;

&FILE1.Close();
&LOGFILE.Close();
/******************************************************************************/
Sample FileLayout Image:
                                                        http://pawan-mundhra.blogspot.com/search/label/File%20Layout
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
There are several ways to insert messages from a list into HTML created in Python, but one common method is to use a template engine like Jinja2. Here is an example: 1. First, install Jinja2 using pip: ``` pip install jinja2 ``` 2. Next, create a template file (e.g. `template.html`) that contains the HTML structure and placeholders for the messages: ```html <!DOCTYPE html> <html> <head> <title>My Chat App</title> </head> <body> <div id="messages"> {% for message in messages %} <p>{{ message }}</p> {% endfor %} </div> </body> </html> ``` In this example, the `{% for %}` and `{% endfor %}` tags define a loop that iterates through each message in the `messages` list and inserts it into a `<p>` tag. 3. In your Python code, load the template file and render it with the list of messages: ```python from jinja2 import Template # Define the list of messages messages = ["Hello", "How are you?", "I'm fine, thank you."] # Load the template file with open("template.html") as file: template = Template(file.read()) # Render the template with the messages html = template.render(messages=messages) # Print or save the HTML output print(html) ``` In this example, the `Template` class from Jinja2 is used to load the contents of the `template.html` file. The `render()` method is then called on the template object, passing in the `messages` list as a parameter. This replaces the `{{ message }}` placeholder in the template with each message in the list, generating the final HTML output. You can then print or save the `html` variable as needed.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值